<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="110px">
      <el-form-item label="使用状态：" class="mr10">
        <el-select v-model="queryParams.status" placeholder="请选择使用状态" clearable class="selWidth">
          <!-- 状态（0：关闭，1：开启） -->
          <el-option label="未使用" value="0" />
          <el-option label="已使用" value="1" />
          <el-option label="已过期" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="优惠券名称：" class="mr10">
        <el-input v-model="queryParams.name" placeholder="请输入优惠劵名称" class="selWidth" clearable>
        </el-input>
      </el-form-item>
      <el-form-item label="用户id：" class="mr10">
        <el-input v-model="queryParams.userId" placeholder="请输入用户id" class="selWidth" clearable>
        </el-input>
      </el-form-item>
      <el-form-item label="用户昵称：" class="mr10">
        <el-input v-model="queryParams.nickName" placeholder="请输入用户昵称" class="selWidth" clearable>
        </el-input>
      </el-form-item>
      <el-form-item label="用户手机号" class="mr10">
        <el-input v-model="queryParams.phoneNo" placeholder="请输入用户手机号" class="selWidth" clearable>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="orderheadList" style="width: 100%">
      <el-table-column prop="couponId" label="优惠券ID" min-width="80" />
      <el-table-column prop="name" label="优惠券名称" min-width="150" />
      <el-table-column prop="nickname" label="用户昵称" min-width="130" />
      <el-table-column prop="userId" label="用户id" min-width="130" />
      <el-table-column prop="phoneNo" label="用户手机号" min-width="130" />
      <el-table-column prop="money" label="面值" min-width="100" />
      <el-table-column prop="minPrice" label="最低消费额" min-width="120" />
      <el-table-column prop="startTime" label="开始使用时间" min-width="150" />
      <el-table-column prop="endTime" label="结束使用时间" min-width="150" />
      <el-table-column label="获取方式" min-width="150">
        <template slot-scope="scope">
          <span>{{scope.row.type | failFilter}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="is_fail" label="是否可用" min-width="100">
        <template slot-scope="scope">
          <i v-if="scope.row.status === 0" class="el-icon-check" style="font-size: 14px;color: #0092DC;" />
          <i v-else class="el-icon-close" style="font-size: 14px;color: #ed5565;" />
        </template>
      </el-table-column>
      <el-table-column label="使用状态" min-width="100">
        <template slot-scope="scope">
          <span>{{scope.row.status | statusFilter}}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>
<script>
  import {
    couponUserList
  } from "@/api/store/coupon";

  export default {
    name: "Orderhead",
    dicts: ['con_value_behavior', ],
    filters: {
      failFilter(status) {
        const statusMap = {
          'receive': '自己领取',
          'send': '后台发送',
          'give': '满赠',
          'new': '新人',
          'buy': '买赠送'
        }
        return statusMap[status]
      },
      statusFilter(status) {
        const statusMap = {
          0: '未使用',
          1: '已使用',
          2: '已过期'
        }
        return statusMap[status]
      }
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 订单表头表格数据
        orderheadList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          uid: '',
          name: '',
          status: '',
          phoneNo:'',
          userId:'',
          nickName:''
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        dateRange: []
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询订单表头列表 */
      getList() {
        let params = {
          status: this.queryParams.status,
          userId: this.queryParams.userId,
          nickName:this.queryParams.nickName,
          name: this.queryParams.name,
          pageSize: this.queryParams.pageSize,
          pageNum: this.queryParams.pageNum,
          phoneNo:this.queryParams.phoneNo
        }
        couponUserList(params).then(res => {
          if (res.code == '200') {
            this.orderheadList = res.rows
          }
          this.total = res.total
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        // this.queryParams = {
        //   uid: '',
        //   name: '',
        //   status: '',
        //   phoneNo:''
        // };
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
         this.queryParams = {
          uid: '',
          name: '',
          status: '',
          phoneNo:''
        };
        this.resetForm("queryForm");
        this.handleQuery();
      },
    }
  };
</script>
<style>
  .br /deep/ .el-descriptions__header {
    display: none !important;
  }

  .ec-input-range-divider {
    width: 10px;
    height: 2px;
    background-color: #333;
    margin: 0 auto;
  }
</style>
